<?php

// $Id$

require_once('tcms_vpage_ci_dbc.class.php');
require_once('tcms_vpt_ci_dbc.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/tcms_ci_type_dbc.class.php');


class TCMS_VPT_CI_Item_Deleter extends Tangra_Class {
	public static function delete(DB_Connection $dbc, $vpt_ci_id, $hidden_inc_path, $current_user_id) {
		$cis = TCMS_VPage_CI_DBC::load_cis_for_vpt_ci($dbc, $vpt_ci_id);
		foreach($cis as $ci) {
			$ci_type = new TCMS_CI_Type_DBC();
			$ci_type->load_by_id($dbc, $ci->get_type());

			$item_class = $ci_type->get_class_name();
			if (!class_exists($item_class)) {
				require_once($hidden_inc_path.$ci_type->get_class_path());
			}
			$item = new $item_class;
			call_user_func_array(array($item_class, 'delete_cascade'), array($dbc, $ci->get_ci_id(), $hidden_inc_path, $current_user_id));
			TCMS_VPage_CI_DBC::delete($dbc, $ci->get_id());
		}


		TCMS_VPT_CI_DBC::delete($dbc, $vpt_ci_id);
	}
}